package net.aiform.template.dao.impl;

import java.util.List;

import net.aiform.template.dao.TemplateDao;
import net.aiform.template.pojo.Template;

import org.apache.log4j.Logger;
import org.springframework.orm.jpa.support.JpaDaoSupport;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@SuppressWarnings("unchecked")
public class TemplateDaoJPA extends JpaDaoSupport implements TemplateDao {
	private Logger log = Logger.getLogger(this.getClass());

	@Override
	public void save(Template template) {
		log.info(template);
		getJpaTemplate().merge(template);
	}

	@Override
	public List<Template> findAll() {
		return getJpaTemplate().find(" FROM Template where 1=1 ");
	}

	@Override
	public Template get(String code) {
		List<Template> list = getJpaTemplate().find(" from Template where code = '" + code + "' ");
		return 0 == list.size() ? null : list.get(0);
	}

	@Override
	public Template get(Integer id) {
		return getJpaTemplate().find(Template.class, id);
	}
}
